package com.hevs.samplewebapp.client.bean;

/**
 * Password Generator
 * <p>Abstract class to provide a systeme to generate a random password</p>
 * @author Thomas
 * @date 26.03.2012
 */

public abstract class PassGenerator {

	// ------------------------------------------------------------
	// VARIABLES
	// ------------------------------------------------------------

	/**
	 * Length minimum of the new password
	 */
	public static final int MIN_LENGTH = 10;

	/**
	 * Random variable for the generation
	 */
	protected static java.util.Random r = new java.util.Random();

	/**
	 * Array of characters valid for the password
	 */
	protected static char[] goodChar = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
		'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
		'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
		'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
		'2', '3', '4', '5', '6', '7', '8', '9', '+', '-', '@', };

	// ------------------------------------------------------------
	// METHODS
	// ------------------------------------------------------------

	/**
	 * Method to generate randomly a 10 characters length password
	 * @return
	 * 	a new password in String format
	 */
	public static String generatePassword(){
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < MIN_LENGTH; i++) {
			sb.append(goodChar[r.nextInt(goodChar.length)]);
		}
		return sb.toString();
	}
}